<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>编辑公共信息</title>
    <%@ include file="inc/css.jsp" %>
</head>
<body>

<div class="wrapper">
    <%@ include file="inc/nav.jsp" %>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">${showText}</h1>
                <h4 style="margin-left: 10px;">——编辑${showText}</h4>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <form class="form-horizontal">
                            <input type="hidden" id="infoId" value="${info.id}"/>
                            <input type="hidden" id="infoType" value="${infoType}"/>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">名称:</label>
                                <div class="col-sm-8" style="padding-top: 5.5px;">
                                    <input type="text" class="form-control" id="name" name="name" maxlength="20" data-rule="required" value="${info.name}" placeholder="请输入名称"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">详情:</label>
                                <div class="col-sm-8" style="padding-top: 5.5px;">
                                    <!-- 百度富文本编辑框 -->
                                    <script id="container" name="content" type="text/plain" style="width:100%; height:150px; line-height: 0px;"></script>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-10" style="text-align: center">
                                    <a href="javascript:void(0)" class="btn btn-success" role="button" onclick="_infoDetail.fn.subInfo()">保存</a>
                                    <a href="backend/info/index?index=${infoType}" class="btn btn-primary" role="button">返回</a>
                                </div>
                            </div>
                        </form>

                        <span style="display: none;" id="spqq">${info.description}</span>
                    </div>
                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<%@ include file="inc/footer.jsp" %>
</body>
</html>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var editor1 = new baidu.editor.ui.Editor();
    editor1.render('container');
    editor1.ready(function () {
        this.setContent($("#spqq").html());
    });
</script>
<script type="text/javascript">
    var _infoDetail = {
        v: {
            id: "_infoDetail",
            list: [],
            dTable: null
        },
        fn: {
            checkData: function () {
                var flag = true;
                var name = $('#name').val();
                var content = editor1.getContent();

                if (null == name || name == '') {
                    $sixmac.notify("请输入名称", "error");
                    flag = false;
                    return;
                }

                if (null == content || content == '') {
                    $sixmac.notify("请输入详情", "error");
                    flag = false;
                    return;
                }

                return flag;
            },
            subInfo: function () {
                // 所有的验证通过后，执行新增操作
                if (_infoDetail.fn.checkData()) {
                    $.post(_basePath + "backend/info/save",
                            {
                                "id": $('#infoId').val(),
                                "name": $('#name').val(),
                                "type": $('#infoType').val(),
                                "content": editor1.getContent()
                            },
                            function (data) {
                                if (data > 0) {
                                    window.location.href = _basePath + "backend/info/index?index=" + $('#infoType').val();
                                } else {
                                    $sixmac.notify("操作失败", "error");
                                }
                            });
                }
            }
        }
    }
</script>